<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">    
<title>签到</title>

<script src="/js/jquery/jquery.min.js"></script>

<link rel="stylesheet" href="../css/bootstrap3/css/bootstrap.min.css">

<link rel="stylesheet" href="../css/style.css">
<link rel="stylesheet" href="../css/qiandao_style.css">

<link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/reset.css"/>
<link rel="stylesheet" href="/css/travelContent.css"/>
<script src="/js/calendar.js"></script>
</head>
<body>
<div class="container">
	<div class="row">
		<div class="col-xs-12 clearPadding">



			<div class="search-head">
				<div class="row nav-search">
					<div class="col">
						<a href="javascript:history.go(-1);">
							<span><i class="fa fa-chevron-left"></i></span>
						</a>
					</div>
					<div class="col">
					</div>
				</div>
			</div>



			<div class=""><img src="../img/reward/qdBanner.jpg" class="img-responsive"></div>
			
			<div class="calendar">
				<div class="calenbox">
					<div id="calendar"></div>
				</div>
				<div class="text-center">
					<button class="btn btn-qiandao" onClick="signIn()">马上签到</button>
				</div>
			</div>
			<div class="padding10">
				<div class="font16 pb10 borderb"><strong>当月签到礼包</strong></div>
				<div class="libaolist">
					<div class="clearfix borderb ptb10">
						<div class="col-xs-9 clearPadding">
							<div class="media">
								<a class="media-left pt3" href="javascript:void(0);" >
									<img src="../img/reward/dou.png" style="width:30px;height:30px;">
								</a>
								<div class="media-body">
									<div class="integral">10天礼包（50积分）</div>
									<div class="text-muted font12">当月签到10天即可领取</div>
								</div>
							</div>
						</div>
						<div class="col-xs-3 clearPadding text-right pt2">
							<button class="btn btn-lingqu point" data-day="10" data-int="50" id="btn1" data-state="10">领取</button>
						</div>
					</div>
					<div class="clearfix borderb ptb10">
						<div class="col-xs-9 clearPadding">
							<div class="media">
								<a class="media-left pt3" href="javascript:void(0);">
									<img src="../img/reward/dou.png" style="width:30px;height:30px;">
								</a>
								<div class="media-body">
									<div class="integral">20天礼包（100积分）</div>
									<div class="text-muted font12">当月签到20天即可领取</div>
								</div>
							</div>
						</div>
						<div class="col-xs-3 clearPadding text-right pt2">
							<button class="btn btn-lingqu point" data-day="20" data-int="100" id="btn2" data-state="20">领取</button>
						</div>
					</div>
					<div class="clearfix borderb ptb10">
						<div class="col-xs-9 clearPadding">
							<div class="media">
								<a class="media-left pt3" href="javascript:void(0);">
									<img src="../img/reward/dou.png" style="width:30px;height:30px;">
								</a>
								<div class="media-body">
									<div class="integral">30天礼包（150积分)</div>
									<div class="text-muted font12">当月签到30天即可领取</div>
								</div>
							</div>
						</div>
						<div class="col-xs-3 clearPadding text-right pt2">
							<button class="btn btn-lingqu point" data-day="30" data-int="150" id="btn3" data-state="30">领取</button>
						</div>
					</div>																								
				</div>
			</div>
		</div>
	</div>
</div>
<div class="maskbox"></div>
<div class="qdbox">
	<div class="text-center text-green font18"><strong id="strong">签到成功！</strong></div>
	<div class="text-center pt10" id="signs">您已经签到&nbsp;<span class="text-green" id="daysCount"></span>&nbsp;天</div>
	<div class="text-center ptb15"><img src="../img/reward/gift.png" style="width:125px;margin-left:20px;"></div>
	<div class="text-center"><button class="btn btn-lottery" id="quchou"><a href="turnlate.html">去抽奖</a></button></div>
</div>

<script>


function  signIn(){
    //发送ajax请求将当前日期存入数据库
    $.post("/days",{date:day2,state:1},function (data) {
        $(".maskbox").fadeIn();
        $(".qdbox").fadeIn();
        $(".maskbox").height($(document).height());
        if(data.succeed){
            $(".reward").click(function () {
                window.location.href="/mine/turnlate.html";
            })
        }else{
            $("#signs").html(data.msg);
        }
    })

}


$(".maskbox").click(function(){
	$(".maskbox").fadeOut();
	$(".qdbox").fadeOut();
	window.location.reload();
});


//评论需要登录,通过user来判断是否已经登录
var user = JSON.parse(sessionStorage.getItem("user"));




//获取当前时间

var day2=getDay();

//定义当前时间
var myDate;

var year;

var month;
//获取今天的时间
function getDay(){
    myDate = new Date();

    year=myDate.getFullYear();    //获取完整的年份(4位,1970-????)
    month=myDate.getMonth()+1;       //获取当前月份(0-11,0代表1月)
    var day=myDate.getDate();
    var clock = year + "-";

    if(month < 10)
        clock += "0";

    clock += month + "-";

    if(day < 10)
        clock += "0";

    clock += day + "";

    return (clock);
}

//定义获取天数
var sumDays;


$(function(){
    var signList=[];
	//ajax获取日历json数据,本月数据
	$.get("/days",{userId:user.id},function (data) {
        console.log(data);

        var signList = $.map(data, function (n) {

            return {"signDay": n.split("-")[2]};


        });
        calUtil.init(signList);
    });

    myDate = new Date();
    year=myDate.getFullYear();
    month=myDate.getMonth()+1;



        $.get("/days/" + user.id + "/state", {date: day2}, function (data) {
            if (data == 10) {
                $("#btn1").attr("disabled", true);

            }else if(data==20){
                $("#btn1").attr("disabled", true);
                $("#btn2").attr("disabled", true);
			}else if(data==30){
                $(".point").attr("disabled",true);
			}


        });


	$.get("/days/"+month,{userId:user.id},function (data) {
	    sumDays=data;
        $("#daysCount").html(sumDays);

        //签到获取积分
        $(".point").click(function () {

            var point=$(this).data("int");
            var days=$(this).data("day");

			var state=$(this).data("state");


            if(sumDays>=days){
                $.ajax({
                    type:'put',
                    url:"/days/"+user.id,
                    data:{"point":point,"state":state},
                    success:function (data) {
                        if(data.succeed){
                            $(".maskbox").fadeIn();
                            $(".qdbox").fadeIn();
                            $(".maskbox").height($(document).height());
                            $("#strong").html("恭喜获取"+point+"个积分");
                            $("#signs").html("");

                        }

                    }
                })
            }

        });


    })



    });
</script>

</body>
</html>
